from flask import Flask, render_template
from flask_socketio import SocketIO, emit

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)


@socketio.on('connect', namespace='/chat')
def test_connect():
    socketio.emit('server_response', {'data': 'connected'}, namespace='/test_conn')
    print('客户端登录')

@socketio.on('disconnect', namespace='/chat')
def test_disconnect():
    print("连接断开")
    print('client disconnected')


if __name__ == '__main__':
    socketio.run(app, host='127.0.0.1', port=8080, debug=True)
